package io.renren.modules.jxgk.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.jxgk.entity.StudentAttendenceInfoEntity;
import io.renren.modules.jxgk.service.StudentAttendenceInfoService;
import io.renren.modules.jxgkphone.tempEntity.TempStudentAttendence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wuwenze.poi.ExcelKit;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("StudentAttendenceInfo/")
public class StudentAttendenceInfoController {

    @Autowired
    StudentAttendenceInfoService studentAttendenceInfoService;

    @RequestMapping("Select")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<StudentAttendenceInfoEntity> cse = studentAttendenceInfoService.queryList(query);
        int total = studentAttendenceInfoService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("/Delete")
    public R delete(@RequestBody String[] indexs){
        studentAttendenceInfoService.deleteBatch(indexs);
        return R.ok();
    }
    @RequestMapping("/Insert")
    public R save(@RequestBody StudentAttendenceInfoEntity ste){
        studentAttendenceInfoService.save(ste);
        return R.ok();
    }
    @RequestMapping("/Info/{index}")
    public R info(@PathVariable("index") String index){
        StudentAttendenceInfoEntity cse = studentAttendenceInfoService.queryObject(index);
        return R.ok().put("StudentAttendenceInfo", cse);
    }
    @SysLog("修改用户")
    @RequestMapping("/Update")
    public R update(@RequestBody StudentAttendenceInfoEntity cse){
        studentAttendenceInfoService.update(cse);
        return R.ok();
    }
    @RequestMapping("/export")
    public R export(HttpServletResponse response, String department) {
        List<StudentAttendenceInfoEntity> cse=null;
        Map<String,Object> map=new HashMap<String,Object>();
        if(department!=null&&!department.equals("")){
            map.put("department",department);
        }
        try{
             cse = studentAttendenceInfoService.queryList(map);
            ExcelKit.$Export(StudentAttendenceInfoEntity.class, response).toExcel(cse, "学生考勤数据");
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok();
    }
}
